package cn.daniellee.plugin.rb;

import cn.daniellee.plugin.rb.listener.BungeeListener;
import cn.daniellee.plugin.rb.listener.PlayerListener;
import org.bukkit.Bukkit;
import org.bukkit.plugin.java.JavaPlugin;

public class ResidenceBungee extends JavaPlugin {

    private static ResidenceBungee instance;

    private boolean bungeecord;

    @Override
    public void onEnable() {
        instance = this;

        getLogger().info(" ");
        getLogger().info(">>>>>>>>>>>>>>>>>>>>>>>> ResidenceBungee Loaded <<<<<<<<<<<<<<<<<<<<<<<<");
        getLogger().info(">>>>> If you encounter any bugs, please contact author's QQ: 768318841 <<<<<");
        getLogger().info(" ");

        Bukkit.getPluginManager().registerEvents(new PlayerListener(), this);

        bungeecord = Bukkit.getServer().spigot().getConfig().getBoolean("settings.bungeecord", false);

        if (bungeecord) {
            this.getServer().getMessenger().registerOutgoingPluginChannel(this, "BungeeCord");
            this.getServer().getMessenger().registerIncomingPluginChannel(this, "BungeeCord", new BungeeListener());
        } else {
            getLogger().info("[ResidenceBungee] This plugin does not work in non-bungee server!");
            Bukkit.getPluginManager().disablePlugin(this);
        }
    }

    @Override
    public void onDisable() {
        if (bungeecord) {
            this.getServer().getMessenger().unregisterOutgoingPluginChannel(this, "BungeeCord");
            this.getServer().getMessenger().unregisterIncomingPluginChannel(this, "BungeeCord");
        }

        getLogger().info(" ");
        getLogger().info(">>>>>>>>>>>>>>>>>>>>>>>> ResidenceBungee Unloaded <<<<<<<<<<<<<<<<<<<<<<<<");
        getLogger().info(" ");
    }

    public static ResidenceBungee getInstance() {
        return instance;
    }

    public boolean isBungeecord() {
        return bungeecord;
    }
}
